package twentytwenty;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2020-12-08 9:23
 * @Modified By:
 */
public class IsHappy_202 {
    public static void main(String [] args){
        int n = 19;
        System.out.println(isHappy(n));
    }

    public static boolean isHappy(int n) {
        Set<Integer> seen = new HashSet<>();
        int fuck;
        while (n != 1 && !seen.contains(n)) {
            seen.add(n);
            int change = n;
            int sum = 0;
            while (change > 0){
                fuck = change % 10;
                change /= 10;
                sum += fuck * fuck;
            }
            n = sum;
        }
        return n == 1;
    }
}
